<?php
/**
 * Created by PhpStorm.
 * Author: ljz
 * Date: 2023/5/17
 * Time: 16:57
 */

namespace App\backend\models;


use App\common\models\BaseModel;
use Illuminate\Support\Facades\DB;

/**
 * Class AdminRoleUsersModel
 * @package app\backend\models
 */
class AdminOperationAllLogModel extends BaseModel
{
    const table = 'admin_operation_all_log';

    public function __construct() {

    }

    /**
     * 数据库 - 查询列表
     * @param $page int //当前页数
     * @param $limit int //分页页数
     * @param $where_data array //查询条件 参数数组
     * @param $where_between array //时间查询条件 参数数组
     * @param $select array //select 查询参数
     * @return array
     */
    static public function listed($page, $limit, $where_data = [], $where_between = [], $select = ['*'])
    {
        $query = DB::table(self::table)
            ->leftJoin('admin_users', 'admin_operation_all_log.admin_id', '=', 'admin_users.id')
            ->select($select)
            ->where($where_data);

        if (!empty($where_between)) {
            $query = $query->whereBetween("admin_operation_all_log.created_at", $where_between);
        }

        $data = $query->apiPaginate($limit, ['*'], 'page', $page)->toArray();
        return $data;
    }

    /**
     * 总后台操作日志
     * 数据库 - 插入数据
     * @param $data //参数数组
     * @return array
     */
    static public function insertData($data)
    {
        $data = DB::table(self::table)->insert($data);
        return $data;
    }

}
